//
//  GoodsCell.swift
//  Box
//
//  Created by mn on 2025/4/1.
//

import UIKit
import SnapKit

class GoodsCell: UITableViewCell {

    let productView = ProductView()
    let freightView = FreightView()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
        contentView.backgroundColor = .white
        contentView.addSubview(productView)

        productView.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
        }
        contentView.addSubview(freightView)

        freightView.snp.makeConstraints { make in
            make.top.equalTo(productView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
    }
    var stashModel: StashModel?{
        didSet{
            guard let stashModel else { return }
            productView.titleLabel.text = stashModel.goodsName
            productView.priceLabel.text = String(format: "¥%.2f", Float(stashModel.price) * 0.01)
            productView.quantityLabel.text = "x\(stashModel.count)"
            productView.productImageView.kf.setImage(with: URL(string: stashModel.imgUrlList.first ?? ""))

        }
    }
}
